﻿#region

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Xml;
using CuongHanh.Helpers;

#endregion

namespace CuongHanh.Models
{
    [Table("tbl_TiGia")]
    public class TiGia : CacheStringClass
    {
        public TiGia()
        {
        }

        public TiGia(XmlElement element)
        {
            Code = element.Attributes["CurrencyCode"].Value;
            Name = element.Attributes["CurrencyName"].Value;
            Buy = ConvertHelper.ToDouble(element.Attributes["Buy"].Value,
                    0);
            Transfer = ConvertHelper.ToDouble(element.Attributes["Transfer"].Value,
                    0);
            Sell = ConvertHelper.ToDouble(element.Attributes["Sell"].Value,
                    0);
        }

        [Key]
        public string Code { get; set; }

        [NotMapped]
        public override string Key
        {
            get
            {
                return Code;
            }
        }

        public string Name { get; set; }

        public double Buy { get; set; }

        public double Transfer { get; set; }

        public double Sell { get; set; }

        [NotMapped]
        public override bool Inactive { get; set; }

        public void UpdateInfoFrom(TiGia model)
        {
            Code = model.Code;
            Name = model.Name;
            Buy = model.Buy;
            Transfer = model.Transfer;
            Sell = model.Sell;
        }
    }
}
